/**
 * 向旧手机号码发送验证码
 */
function ajaxgetCodeToOldPhone(that) {
    var url = "/Lvscore_User_M/account/ajaxgetCodeToOldPhone";
    $.ajax({
        url:url,
        type:"post",
        //timeout:10000,
        success:function (data) {
            //向旧手机号码发送验证码成功之后变为30秒倒计时
            that.disabled = false;
            if (data == '1') {
                alertBox("发送成功，请注意查收");
            } else if (data == '-1') {
                validateSpanMsg("errorMessage","该手机号已注册")
                //alertBox("该手机号已被注册", '');
            } else {
                alertBox("发送失败，请重试", '');
            }
            settime(that);
        },
        error:function(){
            alertBox("网络异常，请重试","");
            //validateSpanMsg("errorMessage","网络异常，请重试");
            $("#get").val("获取验证码");
        },
        dataType:"json"
    });
}
/**
 * 验证旧手机验证码是否输入正确
 * code    用户输入的验证码
 */
function ajaxValidateCodeOldPhone(code) {
    //loading("数据提交中...");
    var url = "/Lvscore_User_M/account/ajaxValidateCodeOldPhone";
    $.ajax({
        url:url,
        type:"post",
        //timeout:10000,
        data:{'code': code},
        success:function (data) {
            //$(".loadingBox").hide();
            if (data == 1) {
                window.location.href = "/Lvscore_User_M/userWeb/views/accounterCenter/newTel.html?code=" + code;
            } else if(data==-1) {
                validateSpanMsg("errorMessage","验证码错误");
            }else{
                alertBox("网络异常，请重试","");
                //validateSpanMsg("errorMessage","网络异常，请重试");
             }
        },
        error:function(){
            //$(".loadingBox").hide();
            alertBox("网络异常，请重试","");
            //validateSpanMsg("errorMessage","网络异常，请重试");
        },
       dataType:"json"
    });
}
$(function () {
    getUrl('accounterCenter/changeTel','accounterCenter/index', 'accounterCenter/newTel');
    $(".code").val("");
    $("#errorMessage").html("");
    var user = getUser_C();
    if (user) {
        $(".tel").text(user.mobile);
    }
    //实时监控验证码的值
    inputChange(".code","#errorMessage");
    $("#get").click(function () {
        $(this).disabled = true;
        $(this).val("发送中...");
        ajaxgetCodeToOldPhone(this);
    });
    function codeMessage(){
        var reg=/^\d{6}$/;
        var code=$(".code").val();
        if (code == null || code == "") {
            validateSpanMsg("errorMessage","请输入验证码");
            return false;
        }else if(!reg.test(code)){
            validateSpanMsg("errorMessage","验证码错误");
            return false;
        }else{
            return true;
        }
    }
    $(".code").blur(function(){
        codeMessage();
    })
    $(".sub").click(function () {
        if (codeMessage())
       {
           ajaxValidateCodeOldPhone($(".code").val());
        }

    });

})
